package br.com.nrti.still.eventos;

import android.content.Context;
import android.content.Intent;
import android.provider.Settings;

public class Aviao {
	public static final String ACAO_AVIAO_NAO_ALTERAR = "NAO";
	public static final String ACAO_AVIAO_DESLIGAR = "DES";
	public static final String ACAO_AVIAO_LIGAR = "LIG";
	public static final String ACAO_AVIAO_VOLTAR_ANTERIOR = "ANT";	
	
	private static Context contexto;

	public static void inicializar(Context context) {
		contexto = context;
	}

	public static boolean isEnabled() {
		return Settings.System.getInt(contexto.getContentResolver(),
				Settings.System.AIRPLANE_MODE_ON, 0) == 1;
	}

	public static void setAtivo() {
		if (isEnabled())
			return;
		
		Settings.System.putInt(contexto.getContentResolver(),
				Settings.System.AIRPLANE_MODE_ON, 1);
		Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
		intent.putExtra("state", 1);
		contexto.sendBroadcast(intent);
	}
	
	public static void setInativo() {
		if (!isEnabled())
			return;
		
		Settings.System.putInt(contexto.getContentResolver(),
				Settings.System.AIRPLANE_MODE_ON, 0);
		Intent intent = new Intent(Intent.ACTION_AIRPLANE_MODE_CHANGED);
		intent.putExtra("state", 0);
		contexto.sendBroadcast(intent);
	}
}
